package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//对自定义对象进行排序
public class SortPoint {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(4,6));
        list.add(new Point(44,7));
        list.add(new Point(6,56));
        list.add(new Point(75,9));
        list.add(new Point(8,10));
        System.out.println("原始数据为"+list);

        Collections.sort(list, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                return o1.getX()-o2.getX();
              //  return o2.getY();-o1.getY();
            }
        });
       Collections.sort(list,(o1,o2)->o1.getX()-o2.getX());
        System.out.println("list后的排序为"+list);


    }
}
